<?php
if(!defined('IN_IBEIKE')) {
	exit('Access Denied');
}

class table_city_reply extends common_table
{
	public function __construct() {

		$this->_table = 'city_reply';
		$this->_pk    = 'rid';

		parent::__construct();
	}
	public function fetch_by_rid($rid){
		if(!empty($rid)&&$rid){
			return DB::fetch_first('SELECT * FROM %t WHERE rid=%d',array($this->_table,$rid));//返回数组包含各个字段的值
		}
		return false;
	}
	public function fetch_all_by_tid($tid,$start=0,$limit=0,$order='ASC'){
		if(!empty($tid)){
			return DB::fetch_all('SELECT * FROM %t WHERE tid=%d ORDER BY rid ASC '.DB::limit($start,$limit),array($this->_table,$tid));
		}
		return false; 
	}
	public function count_by_tid_rid($tid,$rid){
		if(!empty($tid)&&!empty($rid)){
			return DB::result_first('SELECT COUNT(*) FROM %t WHERE tid=%d AND rid>%d '.DB::limit($start,$limit),array($this->_table,$tid,$rid));
		}
		return false;
	}
	public function delete_all_by_rid($rid,$limit="",$unbuffered = true){//按主键删除
		if(!empty($rid)&&$rid){
			$condition=$this->_pk."='".$rid."'";
			return DB::delete($this->_table,$condition,limit,$unbuffered = true);//返回受影响的行数
		}
		return false;
	}
	public function update_by_rid($rid,$data,$unbuffered = false, $low_priority = false){
		if(!empty($rid) && !empty($data)){
			$condition=$this->_pk."='".$rid."'";
			return DB::update($this->_table,$data,$condition,$unbuffered,$low_priority);//返回前一次 MySQL 操作所影响的记录行数
		}
		return false;
	}
	public function insert($data, $return_insert_id = false, $replace = false, $silent = false){
		if(!empty($data)){
			return DB::insert($this->_table,$data, $return_insert_id,$replace,$silent);//返回上一步 INSERT 操作产生的 ID
		}
		return false;
		
	}
	/*
	public function update_intfield_chage_by_rid($rid,$fielddata,$order){//$fielddata是键为字段,值为修改的数目,$order为1增加0减
		if(!empty($rid) && !empty($fielddata) && !empty($order)){
                        $sign="";
			foreach ($fielddata as $k => $v){
				$datakey=$sign.$k;
                                $sign=",";
			}
			$old_num=self::get_intfield_num_by_rid($rid,$datakey);//查询该主键的数字字段值,返回数组
			if($old_num!=false){
				foreach ($fielddata as $k => $v){
					if($order==1){
						$old_num[$k]=$old_num[$k]+$v;
					}else{
						$old_num[$k]=$old_num[$k]-$v;
					}
				}
			}else{
				return false;
			}
			$condition=$this->_pk."='".$rid."'";
			return DB::update($this->_table,$old_num,$condition);//更新数据
		}else{
			return false;
		}
	}
	*/
	public function update_nice_by_rid($rid){
		if(!empty($rid)){
			return DB::query('UPDATE %t SET `nice`=`nice`+1 WHERE rid=%d', array($this->_table, $rid));
		}
	}
/*
	public static function get_intfield_num_by_rid($rid,$datakey){//按主键查询数字类的字段的值为多少
		if(!empty($rid) && !empty($datakey)){
                        return DB::fetch_first('SELECT %s FROM %t WHERE rid=%s',array($datakey,$this->_table,$rid));
		}else{
			return false;
		}
	}
*/
	
}

?>